Skip to content

Set-PkMessageHandler throws in worker code - #95

Merged
HalRiveria-Bot merged 3 commits into
mainfrom
fix/message-handler-in-worker
Dec 1, 2026
Merged

HalRiveria-Bot merged 3 commits into
mainfrom
fix/message-handler-in-worker

Conversation

@HalRiveria-Bot

Copy link
Copy Markdown
Collaborator

A worker could call Set-PkMessageHandler: -SharedFunctionNames accepts it, and the worker-safety check can be off or not see the call. The handler was then a scriptblock made in the worker's runspace, which the main thread ran for every message after that. Running another runspace's scriptblock can hang or crash PowerShell (it's the second of the README's two worker rules).

  • Set-PkMessageHandler throws in worker code, $null included, and leaves the handler as it was. The message says to set it on the main thread before starting the workers.
  • The README's Messages section and the function's help say so.

This changes behavior for a worker that set a handler and got away with it.

Tests

Section M shares the function with a worker that sets a handler, and with one that resets it to $null.

  • On the old code, 5.1 and 7 both fail: Set-PkMessageHandler throws in a worker, for a handler or $null (nothing thrown) and and leaves the handler as it was.
  • With the fix, both pass.
  • Full harness: 706 passed on Windows PowerShell 5.1 and 706 passed on PowerShell 7.6.2, no skips.

🤖 Generated with Claude Code

HalRiveria and others added 3 commits December 1, 2026 16:12
Two of the batch's own closures called Complete-PkProcess and Write-PkMessage
by name. A .GetNewClosure() block only sees global functions, so a batch failed
with "'Complete-PkProcess' is not recognized" when the kit was loaded for one
module only. They're captured up front now, like the private helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker given the function (-SharedFunctionNames takes it) could set a handler
made in its own runspace, which the main thread then ran for every message.
Running another runspace's scriptblock can hang or crash PowerShell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HalRiveria-Bot
HalRiveria-Bot merged commit 07c41ef into main Dec 1, 2026
2 checks passed
@HalRiveria-Bot
HalRiveria-Bot deleted the fix/message-handler-in-worker branch December 1, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants